<?php
class TongjiAction extends Action {
    /**
     * 访问量统计
     * @author 沈威
     * @tel 15005164276
     * @email 403382132@qq.com
     * Enter description here ...
     */
	public function fangwen()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$this->display();
	}
	
	/**
     * 注册量统计
     * @author 沈威
     * @tel 15005164276
     * @email 403382132@qq.com
     * Enter description here ...
     */
	public function zhuce()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$usermodel=M('User');
		$time=time();
/*		 $t3   =   mktime(0,0,0,date("m",$time)-1,1,date("Y",$time)); 
		$map['regtime']=array('between',"$t3,$time");
		$count=$usermodel->where($map)->count();
		$shangtime=$t3-2592000;
		$dap['regtime']=array('between',"$shangtime,$t3");
		$shangcount=$usermodel->where($dap)->count();*/
		$t3   =   mktime(0,0,0,date("m",$time),1,date("Y",$time)); 
		$map['regtime']=array('between',"$t3,$time");
		$count=$usermodel->where($map)->count();
		
		$t3 = mktime(0,0,0,date("m",$time)-1,1,date("Y",$time));
		$t4 = mktime(0,0,0,date("m",$time),1,date("Y",$time));
		$map['regtime']=array('between',"$t3,$t4");		
		$shangcount=$usermodel->where($map)->count();
		
		$this->assign('count',$count);
		$this->assign('shangcount',$shangcount);
		$this->display();	
		
	}
	
	/**
     * 内容添加量统计
     * @author 沈威
     * @tel 15005164276
     * @email 403382132@qq.com
     * Enter description here ...
     */
	public function neirong()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$time=time();
//		$t3   =   mktime(0,0,0,date("m",$time)-1,1,date("Y",$time));
		$t3   =   mktime(0,0,0,date("m",$time),1,date("Y",$time));  
		$picturemodel=M('Picture');
		$videomodel=M('Video');
		$flashmodel=M('Flash');
		$gamemodel=M('Game');
		$articlemodel=M('Article');
		$imagemodel=M('Image');
		$bookmodel=M('book');
		$exhibitsmodel=M('Exhibits');
		$knowledgemodel=M('Knowledge');
		$map['uploadtime']=array('between',"$t3,$time");
		$count_picture=$picturemodel->where($map)->count();
		$count_video=$videomodel->where($map)->count();
		$count_flash=$flashmodel->where($map)->count();
		$count_game=$gamemodel->where($map)->count();
		$count_article=$articlemodel->where($map)->count();
		$count_image=$imagemodel->where($map)->count();
		$count_book=$bookmodel->where($map)->count();
		$count_exhibits=$exhibitsmodel->where($map)->count();
		$count_knowledge=$knowledgemodel->where($map)->count();
		$this->assign('count_picture',$count_picture);
		$this->assign('count_video',$count_video);
		$this->assign('count_flash',$count_flash);
		$this->assign('count_game',$count_game);
		$this->assign('count_article',$count_article);
		$this->assign('count_image',$count_image);
		$this->assign('count_book',$count_book);
		$this->assign('count_exhibits',$count_exhibits);
		$this->assign('count_knowledge',$count_knowledge);
		
//		$shangtime=$t3-2592000;
		$t3 = mktime(0,0,0,date("m",$time)-1,1,date("Y",$time));
		$t4 = mktime(0,0,0,date("m",$time),1,date("Y",$time));
//		$dap['uploadtime']=array('between',"$shangtime,$t3");
		$dap['uploadtime']=array('between',"$t3,$t4");
		$count_picture_shang=$picturemodel->where($dap)->count();
		$count_video_shang=$videomodel->where($dap)->count();
		$count_flash_shang=$flashmodel->where($dap)->count();
		$count_game_shang=$gamemodel->where($dap)->count();
		$count_article_shang=$articlemodel->where($dap)->count();
		$count_image_shang=$imagemodel->where($dap)->count();
		$count_book_shang=$bookmodel->where($dap)->count();
		$count_exhibits_shang=$exhibitsmodel->where($dap)->count();
		$count_knowledge_shang=$knowledgemodel->where($dap)->count();
		$this->assign('count_picture_shang',$count_picture_shang);
		$this->assign('count_video_shang',$count_video_shang);
		$this->assign('count_flash_shang',$count_flash_shang);
		$this->assign('count_game_shang',$count_game_shang);
		$this->assign('count_article_shang',$count_article_shang);
		$this->assign('count_image_shang',$count_image_shang);
		$this->assign('count_book_shang',$count_book_shang);
		$this->assign('count_exhibits_shang',$count_exhibits_shang);
		$this->assign('count_knowledge_shang',$count_knowledge_shang);
		
		$this->display();
	}
	
	/**
     * 下载量统计
     * @author 沈威
     * @tel 15005164276
     * @email 403382132@qq.com
     * Enter description here ...
     */
	public function xiazai()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$time=time();
		$t3   =   mktime(0,0,0,date("m",$time)-1,1,date("Y",$time)); 
		$shangtime=$t3-2592000;
		$picturemodel=M('Picture');
		$videomodel=M('Video');
		$flashmodel=M('Flash');
		$gamemodel=M('Game');
		$articlemodel=M('Article');
		$imagemodel=M('Image');
		$bookmodel=M('book');
		$exhibitsmodel=M('Exhibits');
		$knowledgemodel=M('Knowledge');
		$map['uploadtime']=array('between',"$t3,$time");
		$picturelist=$picturemodel->where($map)->select();
		$videolist=$videomodel->where($map)->select();
		$flashlist=$flashmodel->where($map)->select();
		$gamelist=$gamemodel->where($map)->select();
		$articlelist=$articlemodel->where($map)->select();
		$imagelist=$imagemodel->where($map)->select();
		$booklist=$bookmodel->where($map)->select();
		$exhibitslist=$exhibitsmodel->where($map)->select();
		$knowledgelist=$knowledgemodel->where($map)->select();
		$this->assign('picturelist',$picturelist);
		$this->assign('videolist',$videolist);
		$this->assign('flashlist',$flashlist);
		$this->assign('gamelist',$gamelist);
		$this->assign('articlelist',$articlelist);
		$this->assign('imagelist',$imagelist);
		$this->assign('booklist',$booklist);
		$this->assign('exhibitslist',$exhibitslist);
		$this->assign('knowledgelist',$knowledgelist);
		$dap['uploadtime']=array('between',"$shangtime,$t3");
		$picturelist_shang=$picturemodel->where($dap)->select();
		$videolist_shang=$videomodel->where($dap)->select();
		$flashlist_shang=$flashmodel->where($dap)->select();
		$gamelist_shang=$gamemodel->where($dap)->select();
		$articlelist_shang=$articlemodel->where($dap)->select();
		$imagelist_shang=$imagemodel->where($dap)->select();
		$booklist_shang=$bookmodel->where($dap)->select();
		$exhibitslist_shang=$exhibitsmodel->where($dap)->select();
		$knowledgelist_shang=$knowledgemodel->where($dap)->select();
		$this->assign('picturelist_shang',$picturelist_shang);
		$this->assign('videolist_shang',$videolist_shang);
		$this->assign('flashlist_shang',$flashlist_shang);
		$this->assign('gamelist_shang',$gamelist_shang);
		$this->assign('articlelist_shang',$articlelist_shang);
		$this->assign('imagelist_shang',$imagelist_shang);
		$this->assign('booklist_shang',$booklist_shang);
		$this->assign('exhibitslist_shang',$exhibitslist_shang);
		$this->assign('knowledgelist_shang',$knowledgelist_shang);
		$this->display();
	}
	
	/**
	 * 导出Excel
	 * @author 沈威
	 * @tel 15005164276
	 * @email 403382132@qq.com
	 * Enter description here ...
	 */
	public function daochu()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Excel.PHPExcel");
		$objPHPExcel = new PHPExcel();
		// Set document properties
		// Set document properties
		// Add some data
		//写入数据
		$time=time();
//		$t3   =   mktime(0,0,0,date("m",$time)-1,1,date("Y",$time));
		$t3   =   mktime(0,0,0,date("m",$time),1,date("Y",$time));  
		$picturemodel=M('Picture');
		$videomodel=M('Video');
		$flashmodel=M('Flash');
		$gamemodel=M('Game');
		$articlemodel=M('Article');
		$imagemodel=M('Image');
		$bookmodel=M('book');
		$exhibitsmodel=M('Exhibits');
		$knowledgemodel=M('Knowledge');
		$map['uploadtime']=array('between',"$t3,$time");
		$count_picture=$picturemodel->where($map)->count();
		$count_video=$videomodel->where($map)->count();
		$count_flash=$flashmodel->where($map)->count();
		$count_game=$gamemodel->where($map)->count();
		$count_article=$articlemodel->where($map)->count();
		$count_image=$imagemodel->where($map)->count();
		$count_book=$bookmodel->where($map)->count();
		$count_exhibits=$exhibitsmodel->where($map)->count();
		$count_knowledge=$knowledgemodel->where($map)->count();

//		$shangtime=$t3-2592000;
		$t3 = mktime(0,0,0,date("m",$time)-1,1,date("Y",$time));
		$t4 = mktime(0,0,0,date("m",$time)-1,30,date("Y",$time));
				
//		$dap['uploadtime']=array('between',"$shangtime,$t3");
		$dap['uploadtime']=array('between',"$t3,$t4");
		$count_picture_shang=$picturemodel->where($dap)->count();
		$count_video_shang=$videomodel->where($dap)->count();
		$count_flash_shang=$flashmodel->where($dap)->count();
		$count_game_shang=$gamemodel->where($dap)->count();
		$count_article_shang=$articlemodel->where($dap)->count();
		$count_image_shang=$imagemodel->where($dap)->count();
		$count_book_shang=$bookmodel->where($dap)->count();
		$count_exhibits_shang=$exhibitsmodel->where($dap)->count();
		$count_knowledge_shang=$knowledgemodel->where($dap)->count();
		//设置上方文字
		$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '月份')
            ->setCellValue('B1', '图片')
            ->setCellValue('C1', '视频')
            ->setCellValue('D1', '动漫')
			->setCellValue('E1', '游戏')
			->setCellValue('F1', '文章')
			->setCellValue('G1', '挂图')
			->setCellValue('H1', '图书')
			->setCellValue('I1', '展品')
			->setCellValue('J1', '知识题');
		//设置当月统计
		$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A2', '当月')
            ->setCellValue('B2', $count_picture)
            ->setCellValue('C2', $count_video)
            ->setCellValue('D2', $count_flash)
			->setCellValue('E2', $count_game)
			->setCellValue('F2', $count_article)
			->setCellValue('G2', $count_image)
			->setCellValue('H2', $count_book)
			->setCellValue('I2', $count_exhibits)
			->setCellValue('J2', $count_knowledge);
		
		//设置上月统计
		$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A3', '上月')
            ->setCellValue('B3', $count_picture_shang)
            ->setCellValue('C3', $count_video_shang)
            ->setCellValue('D3', $count_flash_shang)
			->setCellValue('E3', $count_game_shang)
			->setCellValue('F3', $count_article_shang)
			->setCellValue('G3', $count_image_shang)
			->setCellValue('H3', $count_book_shang)
			->setCellValue('I3', $count_exhibits_shang)
			->setCellValue('J3', $count_knowledge_shang);
			
        
		            
		// Rename worksheet
		$objPHPExcel->getActiveSheet()->setTitle('neirongtongji');
		
		
		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);    
            
		// Redirect output to a client’s web browser (Excel5)
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="neirongtongji.xlsx"');
		header('Cache-Control: max-age=0');
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
		$objWriter->save('php://output');
		//echo 1;
	}
	
	/**
	 * 注册页的导出Excel
	 * @author 沈威
	 * @tel 15005164276
	 * @email 403382132@qq.com
	 * Enter description here ...
	 */
	public function daochu_zhuce()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Excel.PHPExcel");
		$objPHPExcel = new PHPExcel();
		$usermodel=M('User');
		$time=time();
		$t3   =   mktime(0,0,0,date("m",$time),1,date("Y",$time)); 
		$map['regtime']=array('between',"$t3,$time");
		$count=$usermodel->where($map)->count();
		
		$t3 = mktime(0,0,0,date("m",$time)-1,1,date("Y",$time));
		$t4 = mktime(0,0,0,date("m",$time)-1,30,date("Y",$time));
		$map['regtime']=array('between',"$t3,$t4");		
		$shangcount=$usermodel->where($map)->count();
		
		//设置上方文字
		$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', '当月')
            ->setCellValue('B1', '上月');
        
        //设置数据
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A2', $count)
            ->setCellValue('B2', $shangcount);
        
        // Rename worksheet
		$objPHPExcel->getActiveSheet()->setTitle('zhucetongji');
		
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="zhucetongji.xlsx"');
		header('Cache-Control: max-age=0');
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
		$objWriter->save('php://output');
	}
}